package com.company.project.web;

import com.company.project.core.LayUiTableJson;
import com.company.project.core.Page;
import com.company.project.core.Result;
import com.company.project.model.Professional;
import com.company.project.service.ProfessionalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/4/6
 */
@RestController
@RequestMapping("professional")
public class ProfessionalController {
    @Autowired
    ProfessionalService professionalService;

    @RequestMapping("/page/manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/professional/professionalList.html");
        return modelAndView;
    }

    @GetMapping("/page/detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/professional/professionalAdd.html");
        return modelAndView;
    }

    @RequestMapping("queryProfessionalPage")
    public LayUiTableJson queryProfessionalPage(String college, String professionalName, @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        Result Result = professionalService.queryProfessionalPage(college,professionalName,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)Result.getData());
        return layUiTableJson;
    }

    @RequestMapping("getProfessional")
    public Result getProfessional(@RequestParam("id") Integer id){
        return professionalService.getProfessional(id);
    }

    @RequestMapping("saveProfessional")
    public Result saveProfessional(Professional professional){
        return professionalService.saveProfessional(professional);
    }

    @RequestMapping("deleteProfessional")
    public Result deleteProfessional(@RequestParam("id") Integer id){
        return professionalService.deleteProfessional(id);
    }
}
